home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / ppt100.zip / LIST1.C < prev    next >
Text File  |  1993-05-01  |  26KB  |  886 lines

  1. /*
  2.  *  File Browse Utility, version 1.4
  3.  *
  4.  *  (c) 1992 Barry Nance
  5.  *
  6.  *  distributed through
  7.  *  BYTE Magazine's Software Corner
  8. */
  9.  
  10. // Original program by Mr. Nance was all incorporated in one file: LIST.C.
  11. // I split it up in order to demonstrate some PPT functionality.
  12. // No substantive changes.   This is the 1st of two source modules,
  13. // LIST1.C and LIST2.c.  There is also a header file, LIST.H.
  14. // Gary L. Levine, Feb/1993.
  15.  
  16. #include <stdio.h>
  17. #include <dos.h>
  18. #include <dir.h>
  19. #include <bios.h>
  20. #include <fcntl.h>
  21. #include <conio.h>
  22. #include <io.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <alloc.h>
  26. #include <process.h>
  27. #include <ctype.h>
  28. #include <share.h>
  29. #include <errno.h>
  30. #include <list.h>
  31.  
  32.  
  33. /************************************/
  34.  
  35. char     *fileprompt = "Filename? ";
  36. char     *inv_arg    = "Invalid command line arguments.";
  37. char     *notfound   = "File not found.";
  38. char     *emptyfile  = "File is empty.";
  39. char     *noaccess   = "File in use.  (Try later)";
  40. char     *presskey   = "Press a key to continue.";
  41.  
  42. char    *help[HELP_LINES] =
  43.             {
  44. "                    File Browser 1.4       (c) 1992 Barry Nance           ",
  45. "                                          BYTE Magazine's Software Corner ",
  46. "                                                                          ",
  47. "      Press:                                                              ",
  48. "  ESC, X, or Q.....Quit                   W.........Toggle line wrap      ",
  49. "  T or HOME........Top of file            H.........Toggle Hex/ASCII      ",
  50. "  B or END.........Bottom of file         D.........Shell to DOS          ",
  51. "  N................Next file              P.........Previous file         ",
  52. "  PgUp or PgDn.....Up/Down a screenful                                    ",
  53. "  ─┘ or Spacebar..Next screenful                                         ",
  54. "  \x1a.............Up/down/right/left                                     ",
  55. "  F................Find text (any case)                                   ",
  56. "  S................Search (exact case)                                    ",
  57. "  A................Find/search again                                      ",
  58. "                                                                          ",
  59. "                                                                          ",
  60. "                          <Press a key to resume>                         "
  61.             };
  62.  
  63. unsigned char string[STR_SIZE];
  64. char        string1[101];
  65.  
  66. char        search_arg[81];
  67. int         search_flag;
  68. int         ignore_case;
  69. int         spos;
  70.  
  71. long        line_number;
  72. long        linenum_save;
  73.  
  74. unsigned char CharCode;
  75. unsigned char ScanCode;
  76.  
  77. int         xesc = FALSE;
  78. int         eof_flag = FALSE;
  79. int         start_of_file = TRUE;
  80. int         line_end_char = 0;
  81. int         hex_mode = FALSE;
  82. int         wrap_mode = FALSE;
  83.  
  84. int         start_save;
  85. int         eof_save;
  86. int         fbufblock_save;
  87. int         fbufndx_save;
  88.  
  89. unsigned    top, left, bottom, right, screen_width, screen_height;
  90. int         left_relative_pos;
  91.  
  92. struct ftime ftimestruc;
  93. struct ffblk findblock;
  94.  
  95. char        filename[80];
  96. char        drive[5];
  97. char        path[81];
  98. char        name[10];
  99. char        ext[5];
  100.  
  101. int         count;
  102. int         flag;
  103. int         file_num;
  104. int         current_row;
  105. int         file_is_empty;
  106.  
  107. int         screen_rcds;
  108. int         screen_lines_hold;
  109. int         screen_lines;
  110. int         lines_read;
  111. int         rcds_read;
  112. int         lines_displayed;
  113.  
  114. unsigned    i, j, k;
  115.  
  116. int         fh;
  117. long        filesize;
  118. long        curr_filepos;
  119. long        temp_long;
  120. unsigned    num_blocks;
  121. int         fbufndx;
  122. int         fbufbytes;
  123. unsigned    fbufblock;
  124.  
  125. char        *filelist_ptr;
  126. char        *list_ptr;
  127. char        *file_buff_ptr;
  128. char        *screen_save_ptr;
  129. char        *dos_screen_save_ptr;
  130.  
  131. char        line_save[160];
  132.  
  133. unsigned char low_inten;
  134. unsigned char high_inten;
  135. unsigned char found_attr;
  136.  
  137. struct  csavetype   cursor_data;
  138. struct  csavetype   my_cpos;
  139. struct  csavetype   dos_cpos;
  140.  
  141. union       REGS regs;
  142.  
  143. static int skip[CSIZE];         /* increment to rightmost occurance of ch */
  144. static int cmap[CSIZE];         /* upper to lowercase character map */
  145.  
  146.  
  147. /************************************/
  148.  
  149. void    main(int argc, char *argv[])
  150.         {
  151.         if (get_video_mode() == 7)
  152.             {
  153.             low_inten   = 0x07;
  154.             high_inten  = 0x0f;
  155.             found_attr  = 0x70;
  156.             }
  157.         else
  158.             {
  159.             low_inten   = 0x02;
  160.             high_inten  = 0x03;
  161.             found_attr  = 0x0C;
  162.             }
  163.  
  164.         file_buff_ptr = malloc(BUFSIZE+10);
  165.         if (file_buff_ptr == NULL)
  166.             {
  167.             printf("Insufficient memory.\n");
  168.             return;
  169.             }
  170.         memset(file_buff_ptr, 0, BUFSIZE+10);
  171.  
  172.         screen_save_ptr = malloc(4000);
  173.         if (screen_save_ptr == NULL)
  174.             {
  175.             free(file_buff_ptr);
  176.             printf("Insufficient memory.\n");
  177.             return;
  178.             }
  179.  
  180.         dos_screen_save_ptr = malloc(4000);
  181.         if (dos_screen_save_ptr == NULL)
  182.             {
  183.             free(file_buff_ptr);
  184.             free(screen_save_ptr);
  185.             printf("Insufficient memory.\n");
  186.             return;
  187.             }
  188.  
  189.         filelist_ptr = calloc(1001, 13);
  190.         if (filelist_ptr == NULL)
  191.             {
  192.             free(file_buff_ptr);
  193.             free(screen_save_ptr);
  194.             free(dos_screen_save_ptr);
  195.             printf("Insufficient memory.\n");
  196.             return;
  197.             }
  198.         list_ptr = filelist_ptr;
  199.         count = 0;
  200.  
  201.         textattr(low_inten);
  202.         gettext(1, 1, 80, 25, screen_save_ptr);
  203.         save_cursor(&cursor_data);
  204.  
  205.         if (argc == 1)
  206.             {
  207.             window(1, 25, 80, 25);
  208.             clrscr();
  209.             window(1,  1, 80, 25);
  210.             top = 1; left = 1; bottom = 24; right = 80;
  211.             textattr(low_inten);
  212.             gotoxy(1, 25);
  213.             cputs(fileprompt);
  214.             gotoxy(11, 25);
  215.             kbdstring(filename, 70);
  216.             goto p30;
  217.             }
  218.  
  219.         if (argc == 2)
  220.             {
  221.             top = 1; left = 1; bottom = 24; right = 80;
  222.             strcpy(filename, argv[1]);
  223.             goto p30;
  224.             }
  225.  
  226.         if (argc == 6)
  227.             {
  228.             top    = atoi(argv[2]);
  229.             left   = atoi(argv[3]);
  230.             bottom = atoi(argv[4]);
  231.             right  = atoi(argv[5]);
  232.             if (top == 0 || left == 0 || bottom == 0 || right == 0)
  233.                 goto p20;
  234.             strcpy(filename, argv[1]);
  235.             goto p30;
  236.             }
  237.  
  238. p20:
  239.         gotoxy(1, 24);
  240.         textattr(high_inten);
  241.         cputs(inv_arg);
  242.         gohome();
  243.  
  244. p30:
  245.         if (strlen(filename) == 0)
  246.             gohome();
  247.  
  248.         if ( (flag = findfirst(filename, &findblock, 0)) != 0 )
  249.             {
  250.             printf("\n%s\n", notfound);
  251.             free(file_buff_ptr);
  252.             free(screen_save_ptr);
  253.             free(dos_screen_save_ptr);
  254.             free(filelist_ptr);
  255.             exit(1);
  256.             }
  257.  
  258.         screen_width  = right - left - 1;
  259.         screen_height = bottom - top - 1;
  260.  
  261.         fnsplit(filename, drive, path, name, ext);
  262.  
  263.         while (flag == 0)
  264.             {
  265.             strcpy(list_ptr, findblock.ff_name);
  266.             list_ptr += 13;
  267.             count++;
  268.             if (count >= 1000)
  269.                 break;
  270.             flag = findnext(&findblock);
  271.             }
  272.         list_ptr  = filelist_ptr;
  273.         file_num = 1;
  274.  
  275. open_a_file:
  276.         drawbox();
  277.  
  278.         fnmerge(filename, drive, path, list_ptr, NULL);
  279.         if (_osmajor < 2)
  280.             fh = open(filename, O_RDONLY | O_BINARY);
  281.         else
  282.             fh = open(filename, O_RDONLY | O_BINARY | O_DENYNONE);
  283.  
  284.         if (fh == -1)
  285.             {
  286.             sound(800);
  287.             delay(100);
  288.             nosound();
  289.             gotoxy(left+1, top+1);
  290.             textattr(high_inten);
  291.             if (errno == ENOENT)
  292.                 cputs(notfound);
  293.             else
  294.                 cputs(noaccess);
  295.             gohome();
  296.             }
  297.  
  298.         getftime(fh, &ftimestruc);
  299.         filesize   = filelength(fh);
  300.         temp_long  = (filesize + (BUFSIZEL - 1l)) / BUFSIZEL;
  301.         num_blocks = (unsigned) temp_long;
  302.  
  303.         start_of_file = TRUE;
  304.         eof_flag  = FALSE;
  305.         fbufblock = 0;
  306.         fbufndx   = 0;
  307.         lseek(fh, 0l, SEEK_SET);
  308.         fbufbytes = read(fh, file_buff_ptr, BUFSIZE);
  309.  
  310.         if (fbufbytes == 0)
  311.             file_is_empty = TRUE;
  312.         else
  313.             file_is_empty = FALSE;
  314.  
  315.         if (strchr(file_buff_ptr, LINEFEED) != NULL)
  316.             line_end_char = LINEFEED;
  317.         else
  318.             line_end_char = CR;
  319.  
  320.         textattr(high_inten);
  321.         window(1, 25, 80, 25);
  322.         clrscr();
  323.         window(1, 1, 80, 25);
  324.         gotoxy(1, 25);
  325.         cprintf(
  326. "Line:       [            ]  %9ld bytes  %2d/%2d/%2d %2d:%2.2d:%2.2d  (F1=help)   ",
  327.                       filesize,
  328.                 (int) ftimestruc.ft_month,
  329.                 (int) ftimestruc.ft_day,
  330.                 (int) ftimestruc.ft_year + 80,
  331.                 (int) ftimestruc.ft_hour,
  332.                 (int) ftimestruc.ft_min,
  333.                 (int) ftimestruc.ft_tsec);
  334.  
  335.         gotoxy(14, 25);
  336.         textattr(high_inten);
  337.         strcpy(string, list_ptr);
  338.         while (strlen(string) < 12)
  339.             strcat(string, " ");
  340.         cputs(string);
  341.  
  342.         gotoxy(80, 25);
  343.  
  344.         CharCode = 0;
  345.         ScanCode = HOMEKEY;
  346.         showfile();
  347.  
  348. get_key:
  349.         getkey();
  350.  
  351.         if (   CharCode == 'X' 
  352.             || CharCode == 'x'
  353.             || CharCode == 'Q'
  354.             || CharCode == 'q'
  355.             || CharCode == ESC)
  356.                 {
  357.                 close(fh);
  358.                 xesc = TRUE;
  359.                 gohome();
  360.                 }
  361.  
  362.         if (CharCode == 'T' || CharCode == 't')
  363.             {
  364.             CharCode = 0;
  365.             ScanCode = HOMEKEY;
  366.             }
  367.         else
  368.         if (CharCode == 'B' || CharCode == 'b')
  369.             {
  370.             CharCode = 0;
  371.             ScanCode = ENDKEY;
  372.             }
  373.  
  374.         if (CharCode == 'H' || CharCode == 'h')
  375.             {
  376.             lines_read  = 0;
  377.             rcds_read   = 0;
  378.             wrap_mode = FALSE;
  379.             if (hex_mode)
  380.                 {
  381.                 hex_mode = FALSE;
  382.                 line_number = -1L;
  383.                 while (rcds_read < (bottom - top - 1) / 2)
  384.                     if (fprevrecord() == -1)
  385.                         break;
  386.                 }
  387.             else
  388.                 {
  389.                 while (rcds_read < screen_rcds)
  390.                     if (fprevrecord() == -1)
  391.                         break;
  392.                 hex_mode = TRUE;
  393.                 }
  394.             CharCode = 255;
  395.             showfile();
  396.             goto get_key;
  397.             }
  398.  
  399.         if (CharCode == 'W' || CharCode == 'w')
  400.             {
  401.             if (hex_mode)
  402.                 goto get_key;
  403.             rcds_read  = 0;
  404.             lines_read = 0;
  405.             while (rcds_read < screen_rcds)
  406.                 if (fprevrecord() == -1)
  407.                     break;
  408.             if (wrap_mode)
  409.                 wrap_mode = FALSE;
  410.             else
  411.                 wrap_mode = TRUE;
  412.             CharCode = 255;
  413.             line_number = -1L;
  414.             showfile();
  415.             goto get_key;
  416.             }
  417.  
  418.         if ( CharCode == '?' || (CharCode == 0 && ScanCode == F1) )
  419.             {
  420.             gettext(1, 1, 80, 25, dos_screen_save_ptr);
  421.             save_cursor(&dos_cpos);
  422.             textattr(low_inten);
  423.             window(left+1, top+1, right-1, bottom-1);
  424.             clrscr();
  425.             window(1, 1, 80, 25);
  426.             for (k=0; k<HELP_LINES; k++)
  427.                 {
  428.                 if (k+4 >= bottom) break;
  429.                 gotoxy(2, k+3);
  430.                 cputs(help[k]);
  431.                 }
  432.             gotoxy(80, 25);
  433.             getkey();
  434.             puttext(1, 1, 80, 25, dos_screen_save_ptr);
  435.             restore_cursor(&dos_cpos);
  436.             goto get_key;
  437.             }
  438.  
  439.         if (CharCode == 'D' || CharCode == 'd')
  440.             {
  441.             gettext(1, 1, 80, 25, dos_screen_save_ptr);
  442.             save_cursor(&dos_cpos);
  443.             puttext(1, 1, 80, 25, screen_save_ptr);
  444.             restore_cursor(&cursor_data);
  445.             textattr(high_inten);
  446.             printf("\n");
  447.             printf(
  448. "         ╔════════════════════════════════════════════════╗   \n");
  449.             printf(
  450. "         ║       Type EXIT to resume file browsing.       ║   \n");
  451.             printf(
  452. "         ╚════════════════════════════════════════════════╝   \n");
  453.             textattr(low_inten);
  454.             system("");
  455.             puttext(1, 1, 80, 25, dos_screen_save_ptr);
  456.             restore_cursor(&dos_cpos);
  457.             goto get_key;
  458.             }
  459.  
  460.         if (CharCode == 'N' || CharCode == 'n')
  461.             {
  462.             if (file_num < count)
  463.                 {
  464.                 close(fh);
  465.                 list_ptr += 13;
  466.                 file_num++;
  467.                 goto open_a_file;
  468.                 }
  469.             goto get_key;
  470.             }
  471.  
  472.         if (CharCode == 'P' || CharCode == 'p')
  473.             {
  474.             if (file_num > 1)
  475.                 {
  476.                 close(fh);
  477.                 list_ptr -= 13;
  478.                 file_num--;
  479.                 goto open_a_file;
  480.                 }
  481.             goto get_key;
  482.             }
  483.  
  484.         if (CharCode == 0 || CharCode == 0xE0)
  485.             if (   ScanCode == HOMEKEY
  486.                 || ScanCode == ENDKEY
  487.                 || ScanCode == PGUPKEY
  488.                 || ScanCode == PGDNKEY
  489.                 || ScanCode == UPKEY
  490.                 || ScanCode == DOWNKEY
  491.                 || ScanCode == LEFTKEY
  492.                 || ScanCode == RIGHTKEY)
  493.                     {
  494.                     showfile();
  495.                     goto get_key;
  496.                     }
  497.  
  498.         if (   CharCode == ' ' || CharCode == CR)
  499.                 {
  500.                 showfile();
  501.                 goto get_key;
  502.                 }
  503.  
  504.         if (CharCode == 'F' || CharCode == 'f'
  505.             || CharCode == 'S' || CharCode == 's'
  506.             || CharCode == 'A' || CharCode == 'a')
  507.             {
  508.             find_text();
  509.             goto get_key;
  510.             }
  511.  
  512.         goto get_key;
  513.         }
  514.  
  515. /************************************/
  516.  
  517. void    drawbox(void)
  518.         {
  519.         int      i;
  520.  
  521.         textattr(low_inten);
  522.         window(left, top, right, bottom);
  523.         clrscr();
  524.         window(1, 1, 80, 25);
  525.         gotoxy(left, top);
  526.         textattr(high_inten);
  527.         cprintf("┌");
  528.  
  529.         gotoxy(left+1, top);
  530.         cprintf("%.*s", (right - left) - 1,
  531. "────────────────────────────────────────────────────────────────────────────────");
  532.  
  533.         gotoxy(right, top);
  534.         cprintf("┐");
  535.  
  536.         for (i=top+1; i<bottom; i++)
  537.             {
  538.             gotoxy(left, i);
  539.             cprintf("│");
  540.             gotoxy(right, i);
  541.             cprintf("│");
  542.             }
  543.  
  544.         gotoxy(left, bottom);
  545.         cprintf("└");
  546.  
  547.         gotoxy(left+1, bottom);
  548.         cprintf("%.*s", (right - left) - 1,
  549. "────────────────────────────────────────────────────────────────────────────────");
  550.  
  551.         gotoxy(right, bottom);
  552.         cprintf("┘");
  553.         }
  554.  
  555. /************************************/
  556.  
  557. void    find_text(void)
  558.         {
  559.         gettext(1, 25, 80, 25, line_save);
  560.         save_cursor(&my_cpos);
  561.         window(1, 25, 80, 25);
  562.         clrscr();
  563.         window(1,  1, 80, 25);
  564.         if ( strlen(search_arg) < 1 
  565.           || (CharCode != 'A' && CharCode != 'a') )
  566.             {
  567.             textattr(high_inten);
  568.             gotoxy(1, 25);
  569.             if (CharCode == 'S' || CharCode == 's')
  570.                 {
  571.                 ignore_case = FALSE;
  572.                 cputs("Find(case-sen): ");
  573.                 gotoxy(17, 25);
  574.                 }
  575.             else
  576.                 {
  577.                 ignore_case = TRUE;
  578.                 cputs("Find: ");
  579.                 gotoxy(7, 25);
  580.                 }
  581.             kbdstring(search_arg, 50);
  582.             if (strlen(search_arg) < 1)
  583.                 {
  584.                 puttext(1, 25, 80, 25, line_save);
  585.                 restore_cursor(&my_cpos);
  586.                 return;
  587.                 }
  588.             }
  589.         fbufblock_save = fbufblock;
  590.         fbufndx_save   = fbufndx;
  591.         start_save     = start_of_file;
  592.         eof_save       = eof_flag;
  593.         linenum_save   = line_number;
  594.         search_setup(search_arg, strlen(search_arg), ignore_case);
  595.         search_flag = 1;
  596.         if (line_number == 1L
  597.             && (CharCode != 'A' || CharCode != 'a'))
  598.             {
  599.             start_of_file = TRUE;
  600.             eof_flag  = FALSE;
  601.             fbufblock = 0;
  602.             fbufndx   = 0;
  603.             lseek(fh, 0l, SEEK_SET);
  604.             fbufbytes = read(fh, file_buff_ptr, BUFSIZE);
  605.             }
  606.         lines_read = 0;
  607.         gotoxy(1, 25);
  608.         clreol();
  609.         cputs("Looking... ");
  610.         while (1)
  611.             {
  612.             if (fgetrecord(string, STR_SIZE) == -1)
  613.                 {
  614.                 gotoxy(1, 25);
  615.                 cputs("Not found.  <Press a key>");
  616.                 gotoxy(80, 25);
  617.                 getkey();
  618.                 break;
  619.                 }
  620.             if ( (spos = search(search_arg, strlen(search_arg),
  621.                           string, strlen(string))) != -1)
  622.                 {
  623.                 line_number = -1L;
  624.                 search_flag = 2;
  625.                 if (!wrap_mode && !hex_mode)
  626.                     if (spos > left_relative_pos + screen_width)
  627.                         {
  628.                         left_relative_pos = spos - (screen_width / 2);
  629.                         left_relative_pos = max(0, spos);
  630.                         }
  631.                     else
  632.                         {
  633.                         left_relative_pos = 0;
  634.                         }
  635.                 break;
  636.                 }
  637.             }
  638.         puttext(1, 25, 80, 25, line_save);
  639.         restore_cursor(&my_cpos);
  640.         if (search_flag == 2)
  641.             {
  642.             showfile();
  643.             }
  644.         else
  645.             {
  646.             line_number   = linenum_save;
  647.             start_of_file = start_save;
  648.             eof_flag  = eof_save;
  649.             fbufblock = fbufblock_save;
  650.             fbufndx   = fbufndx_save;
  651.             lseek(fh, ((long) fbufblock) * BUFSIZEL, SEEK_SET);
  652.             fbufbytes = read(fh, file_buff_ptr, BUFSIZE);
  653.             }
  654.         search_flag = 0;
  655.         }
  656.  
  657. /************************************/
  658.  
  659. void    adjust_line_number(int amount)
  660.         {
  661.         if (line_number == -1L)
  662.             return;
  663.  
  664.         line_number += amount;
  665.         if (line_number < 1L)
  666.             line_number = 1L;
  667.         }
  668.  
  669. /************************************/
  670.  
  671. void    showfile(void)
  672.         {
  673.         if (search_flag == 2)
  674.             {
  675.             rcds_read = 0;
  676.             lines_read = 0;
  677.             while (lines_read < screen_lines / 2)
  678.                 if (fprevline() == -1)
  679.                     break;
  680.             fill_window();
  681.             show_line_num();
  682.             return;
  683.             }
  684.  
  685.         if (ScanCode == HOMEKEY)
  686.             {
  687.             left_relative_pos = 0;
  688.             line_number = 1L;
  689.             start_of_file = TRUE;
  690.             eof_flag  = FALSE;
  691.             fbufblock = 0;
  692.             fbufndx   = 0;
  693.             if (filesize == 0l)
  694.                 {
  695.                 sound(800);
  696.                 delay(100);
  697.                 nosound();
  698.                 gotoxy(left+1, top+1);
  699.                 textattr(high_inten);
  700.                 cputs(emptyfile);
  701.                 return;
  702.                 }
  703.             else
  704.                 {
  705.                 lseek(fh, 0l, SEEK_SET);
  706.                 fbufbytes = read(fh, file_buff_ptr, BUFSIZE);
  707.                 fill_window();
  708.                 show_line_num();
  709.                 }
  710.             return;
  711.             }
  712.  
  713.         if (file_is_empty)
  714.             return;
  715.  
  716.         if (ScanCode == PGUPKEY)
  717.             {
  718.             if (line_number == 1L)
  719.                 return;
  720.             rcds_read  = 0;
  721.             lines_read = 0;
  722.             while (lines_read < screen_lines)
  723.                 if (fprevline() == -1)
  724.                     {
  725.                     lines_read = 0;
  726.                     while (lines_read < screen_lines)
  727.                         if (fgetline(string, STR_SIZE) == -1)
  728.                             break;
  729.                     return;
  730.                     }
  731.             lines_read = 0;
  732.             rcds_read  = 0;
  733.             while (lines_read < bottom - top - 1)
  734.                 if (fprevline() == -1)
  735.                     {
  736.                     line_number = 1L;
  737.                     break;
  738.                     }
  739.             adjust_line_number(rcds_read * -1);
  740.             fill_window();
  741.             show_line_num();
  742.             return;
  743.             }
  744.  
  745.         if (ScanCode == PGDNKEY)
  746.             {
  747.             if (eof_flag)
  748.                 return;
  749.             rcds_read = 0;
  750.             screen_lines_hold = screen_lines;
  751.             fill_window();
  752.             adjust_line_number(screen_lines_hold);
  753.             show_line_num();
  754.             return;
  755.             }
  756.  
  757.         if (ScanCode == UPKEY)
  758.             {
  759.             if (line_number == 1L)
  760.                 return;
  761.             rcds_read  = 0;
  762.             lines_read = 0;
  763.             while (lines_read < screen_lines)
  764.                 if (fprevline() == -1)
  765.                     {
  766.                     lines_read  = 0;
  767.                     while (lines_read < screen_lines)
  768.                         if (fgetline(string, STR_SIZE) != -1)
  769.                             break;
  770.                     return;
  771.                     }
  772.             if (fprevline() != -1)
  773.                 {
  774.                 fgetline(string, STR_SIZE);
  775.                 scroll_dn(1);
  776.                 textattr(low_inten);
  777.                 current_row = top + 1;
  778.                 if (hex_mode)
  779.                     display_hex();
  780.                 else
  781.                     display_line();
  782.                 adjust_line_number(-1);
  783.                 }
  784.             rcds_read  = 0;
  785.             lines_read = 0;
  786.             while (lines_read < screen_lines - 1)
  787.                 if (fgetline(string, STR_SIZE) == -1)
  788.                     break;
  789.             show_line_num();
  790.             return;
  791.             }
  792.  
  793.         if (ScanCode == DOWNKEY)
  794.             {
  795.             if (eof_flag)
  796.                 return;
  797.             rcds_read  = 0;
  798.             lines_read = 0;
  799.             if (fgetline(string, STR_SIZE) != -1)
  800.                 {
  801.                 scroll_up(1);
  802.                 textattr(low_inten);
  803.                 current_row = bottom - 1;
  804.                 if (hex_mode)
  805.                     display_hex();
  806.                 else
  807.                     display_line();
  808.                 adjust_line_number(1);
  809.                 show_line_num();
  810.                 }
  811.             return;
  812.             }
  813.  
  814.         if (ScanCode == LEFTKEY)
  815.             {
  816.             if (left_relative_pos == 0)
  817.                 return;
  818.             if (hex_mode || wrap_mode)
  819.                 return;
  820.             movetext(left+1, top+1, right-6, bottom-1, 
  821.                         left+6, top+1);
  822.             left_relative_pos -= 5;
  823.             rcds_read  = 0;
  824.             lines_read = 0;
  825.             while (lines_read < screen_lines)
  826.                 if (fprevline() == -1)
  827.                     break;
  828.             fill_window();
  829.             show_line_num();
  830.             return;
  831.             }
  832.  
  833.         if (ScanCode == RIGHTKEY)
  834.             {
  835.             if (hex_mode || wrap_mode)
  836.                 return;
  837.             if (left_relative_pos >= STR_SIZE - screen_width - 1)
  838.                 return;
  839.             left_relative_pos += 5;
  840.             rcds_read  = 0;
  841.             lines_read = 0;
  842.             while (lines_read < screen_lines)
  843.                 if (fprevline() == -1)
  844.                     break;
  845.             fill_window();
  846.             show_line_num();
  847.             return;
  848.             }
  849.  
  850.         if (CharCode == CR || CharCode == 255 || CharCode == ' ')
  851.             {
  852.             if (eof_flag)
  853.                 return;
  854.             if (CharCode == CR || CharCode == 255)
  855.                 left_relative_pos = 0;
  856.             screen_lines_hold = screen_lines;
  857.             rcds_read  = 0;
  858.             lines_read = 0;
  859.             fill_window();
  860.             if (CharCode != 255)
  861.                 adjust_line_number(screen_lines_hold);
  862.             show_line_num();
  863.             return;
  864.             }
  865.  
  866.         if (ScanCode == ENDKEY)
  867.             {
  868.             left_relative_pos = 0;
  869.             line_number = -1L;
  870.             start_of_file = FALSE;
  871.             fbufblock = num_blocks - 1;
  872.             lseek(fh, ((long) fbufblock) * BUFSIZEL, SEEK_SET);
  873.             fbufbytes = read(fh, file_buff_ptr, BUFSIZE);
  874.             fbufndx = fbufbytes - 1;
  875.             rcds_read  = 0;
  876.             lines_read = 0;
  877.             while (lines_read < bottom - top - 2)
  878.                 if (fprevline() == -1)
  879.                     break;
  880.             fill_window();
  881.             show_line_num();
  882.             return;
  883.             }
  884.         }
  885.  
  886.